package com.fzn.spring5.aopanno;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

/**
 * @program: spring5_demo4
 * 描述：  增强的类
 *  注解 @Aspect 生成代理对象
 * @author: fzn
 * @create: 2022-02-27 12:24
 **/
@Component
@Aspect
public class UserProxy {
    /**
     * 相同的切入点抽取
     */
    @Pointcut(value = "execution(* com.fzn.spring5.aopanno.User.add(..))")
    public void pointdemo() {
    }

    /**
     * 前置通知
     * 切入点表达式
     */
    @Before(value = "pointdemo()")
    public void before(){
        System.out.println("before....");
    }

    /**
     * 在方法执行之后执行
     * 最终通知
     */
    @After(value = "execution(* com.fzn.spring5.aopanno.User.add(..))")
    public void after(){
        System.out.println("after....");
    }

    /**
     * 在返回值之后执行
     * 后置通知
     */
    @AfterReturning(value = "execution(* com.fzn.spring5.aopanno.User.add(..))")
    public void afterReturning(){
        System.out.println("afterReturning....");
    }

    /**
     * 异常通知
     */
    @AfterThrowing(value = "execution(* com.fzn.spring5.aopanno.User.add(..))")
    public void afterThrowing(){
        System.out.println("afterThrowing....");
    }

    /**
     * 环绕通知
     */
    @Around(value = "execution(* com.fzn.spring5.aopanno.User.add(..))")
    public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
        System.out.println("环绕之前....");
        // 别增强的方法
        proceedingJoinPoint.proceed();
        System.out.println("环绕之后....");
    }
}